package com.onesports.intelligent.k12.polarlight.service.index;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.onesports.intelligent.k12.polarlight.domain.dto.index.HomeDTO;
import com.onesports.intelligent.k12.polarlight.domain.entity.report.OperationHomePage;
import com.onesports.intelligent.k12.polarlight.domain.vo.report.OperationHomePageVO;
import com.onesports.intelligent.k12.polarlight.mapper.report.OperationHomePageMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author FPH
 * @since 2022年7月19日10:53:51
 */
@Service
@RequiredArgsConstructor
public class OperationHomePageService extends ServiceImpl<OperationHomePageMapper, OperationHomePage> {

    /**
     * 获取运营端简报
     * @return
     */
    public OperationHomePageVO getList(HomeDTO dto){
//        Date lastDate = new Date(dto.getDate().getTime() + 30 * 60 * 1000);
        OperationHomePage operationHomePage = list(new LambdaQueryWrapper<OperationHomePage>()
//                .ge(OperationHomePage::getCreatedDate,dto.getDate())
//                .le(OperationHomePage::getStatisticalTime,lastDate)
                .orderByDesc(OperationHomePage::getStatisticalTime))
                .stream().findFirst().orElse(new OperationHomePage());
        OperationHomePageVO operationHomePageVO = new OperationHomePageVO();
        BeanUtils.copyProperties(operationHomePage,operationHomePageVO);
        return operationHomePageVO;
    }
}
